package com.hk.controller;

import com.hk.service.business.ImportOrExportFileBusiness;
import com.hk.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author: dpb
 * @date: 2022/11/30
 */
@RestController
@RequestMapping("/file")
public class FilesOperationController {

    @Autowired
    private ImportOrExportFileBusiness importOrExportFileBusiness;


    @PostMapping("/import")
    public R importFile(@RequestParam("file") MultipartFile file) throws Exception {
        return importOrExportFileBusiness.importFile(file);
    }


    @PostMapping("/importFileCountDownSync")
    public R uploadFileSync(@RequestParam("file") MultipartFile file) throws Exception {
        return importOrExportFileBusiness.importFileCountDownSync(file);
    }


    @PostMapping("/uploadFileFutureSync")
    public R importFileFutureSync(@RequestParam("file") MultipartFile file) throws Exception {
        return importOrExportFileBusiness.importFileFutureSync(file);
    }



    @PostMapping("/export")
    public void exportFile(HttpServletResponse response) throws IOException {
        importOrExportFileBusiness.exportFile(response);
    }




}
